<?php
/**
 * Created by PhpStorm.
 * User: asus
 * Date: 2017/6/15
 * Time: 0:22
 */

namespace Mytype\Controller;
use Common\Controller\AdminbaseController;

class SetController extends AdminbaseController
{
    public function index()
    {
        $post = i('post.');
        $this->assign('vo',M('web')->find(1));
        if(IS_POST){
            if(trim(empty($post['title']))){
                $this->error('网站title不能为空');
            }
            if(trim(empty($post['name']))){
                $this->error('网站名称不能为空');
            }
            if(trim(empty($post['key']))){
                $this->error('网站关键词不能为空');
            }
            if(trim(empty($post['des']))){
                $this->error('网站描述不能为空');
            }
            if(trim(empty($post['wechat']))){
                $this->error('客服微信不能为空');
            }
            if(trim(empty($post['number']))){
                $this->error('客服电话不能为空');
            }
            if(trim(empty($post['logo']))){
                $this->error('网站logo不能为空');
            }
            $data = [
                'title'=>$post['title'],
                'name'=>$post['name'],
                'key'=>$post['key'],
                'des'=>$post['des'],
                'wechat'=>$post['wechat'],
                'number'=>$post['number'],
                'logo'=>$post['logo']
            ];
            if(M('web')->where(['id'=>1])->save($data)){
                $this->success('成功');
            }else{
                $this->error('失败，未知错误');
            }
        }else{
            $this->display();
        }

    }
}